/********************************************************************************
 *  Project   : DTP Asset Creation
 *
 *  System    : Digital Traceability Platform
 *
 *  File      : DtpEjbDemo.java
 *
 *  XXXX-XXX  (C) Copyright IBM Japan, Ltd. 2010
 *  XXXX-XXX  (C) Copyright IBM Corp. 2010
 *  All Rights Reserved.
 *  
 *  Version	Date		Author		Comment
 *  -------	----------	----------	------------------------------------------
 *  1.00.00	Aug 6, 2010	yaoqi	新規作成
 ********************************************************************************/
package com.ibm.dtp.ejb.session.impl;
import java.util.Date;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.jws.WebMethod;
import javax.jws.WebService;

import com.ibm.dtp.base.ws.EventRequest;
import com.ibm.dtp.base.ws.EventResponse;
import com.ibm.dtp.base.ws.WSRequest;
import com.ibm.dtp.base.ws.WSResponse;
import com.ibm.dtp.ejb.crud.CrudService;
import com.ibm.dtp.ejb.crud.DynamicQueryParameter;
import com.ibm.dtp.ejb.entity.Event;
import com.ibm.dtp.ejb.session.iface.DemoService;

/**
 * TODO
 *
 * @version 1.00.00 Aug 6, 2010
 * @author yaoqi
 *
 */
@Stateless(name="ejb/dtp/DtpEjbDemo")
//@WebService
@TransactionAttribute( value = TransactionAttributeType.REQUIRED)
public class DtpEjbDemo implements DemoService{
	
	@EJB
	public CrudService crudService; 
	/* (non-Javadoc)
	 * @see com.ibm.dtp.ejb.session.iface.HelloService#sayHello(java.lang.String)
	 */
//	@WebMethod
	public WSResponse getEventSource(WSRequest request) {
		WSResponse result =new WSResponse();
//		List<Event> list = crudService.findWithNamedQuery("getEventSource",
//				QueryParameter.with("event_id", request.getEvent_id()).parameters());
		List<Event> list = crudService.findByDynamicQuery(Event.class,  
				DynamicQueryParameter.with("event_id",  request.getEvent_id()).or("event_id", 2).parameters());
		
		Event e = (Event)list.get(0);
		result.setE_source(e.getSource());
		return result;
	}
	
//	@WebMethod
	public EventResponse getActionResponse(EventRequest request) {
		EventResponse result =new EventResponse();
		result.setLangCD("ja");
		result.setSearchMode("5");
		result.setCurrentTime(new Date());
		result.setErrorCD("0");
		result.setErrorMessage("no message");
		return result;
	}

}
